#ifndef OMNI_LIGHT_3D_HPP
#define OMNI_LIGHT_3D_HPP
#include "Object3D.hpp"


class OmniLight3D : public Object3D
{
public:
	const Shader* shader;
	//OmniLight3D(flecs::entity entity_, uint8_t num, const ShaderObjects* shader, const Color& color, float power = 20.f) : Object3D(entity_), shader(shader)
	//{
	//	shader->use();
	//	getEntity().set<uint8_t>(num);
	//	setPower(power);
	//	setColor(color);
	//};
	OmniLight3D(const flecs::world& w, flecs::entity ecs, const Shader* shader, std::string modelPath = "") : Object3D(w, ecs, modelPath), shader(shader) {};
	OmniLight3D(const flecs::world& w, flecs::entity ecs, uint8_t num, const Shader* shader, const vec3& color, float power, std::string modelPath = "") : Object3D(w, ecs, modelPath), shader(shader)
	{
		shader->use();
		getEntity().set<uint8_t>(num);
		setPower(power);
		setColor(color);
	};
	OmniLight3D(std::string name, const flecs::entity ecs, uint8_t num, const Shader* shader, const vec3& color, float power, std::string modelPath = "") : Object3D(name, ecs, modelPath), shader(shader)
	{
		shader->use();
		getEntity().set<uint8_t>(num);
		setPower(power);
		setColor(color);
	}

	inline const uint8_t getID()
	{
		return *getEntity().get<uint8_t>();
	}
	inline const float   getPower()
	{
		return *getEntity().get<float, tagPower>();
	}
	inline const vec3* getColor()
	{
		return getEntity().get<vec3, tagColor>();
	}

	inline void teleport(const glm::vec3& position)
	{
		glm::mat4 mat = *getMatrix();
		mat[3] = glm::vec4(position, mat[3].w);

		getEntity().set<mat4>(mat)
			.set<vec3, tagPosition>(position);
		shader->setVec3("omnilights[" + std::to_string(getID()) + "].position", getPosition());
	}
	inline void move(const glm::vec3& move)
	{
		getEntity().set<vec3, tagPosition>(getPosition() + move)
			.set<mat4>(glm::translate(*getMatrix(), move));
		shader->setVec3("omnilights[" + std::to_string(getID()) + "].position", getPosition());
	}
	inline virtual void setPower(float power)
	{
		getEntity().set<float, tagPower>(power);
		shader->setFloat("omnilights[" + std::to_string(getID()) + "].power", power);
	}
	inline virtual void setColor(const vec3& color)
	{
		getEntity().set<vec3, tagColor>(color);

		shader->setVec3("omnilights[" + std::to_string(getID()) + "].specular", color * glm::vec3(1.0f));
		shader->setVec3("omnilights[" + std::to_string(getID()) + "].diffuse",  color * glm::vec3(0.8f));
		shader->setVec3("omnilights[" + std::to_string(getID()) + "].ambient",  color * glm::vec3(0.2f));
	}
};

#endif // OMNI_LIGHT_3D_HPP